package com.bappi.utils;

import com.tos.quran.R;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;

public class AlertUtils {
//	public static final ProgressDialog getProgressDialog(Context context,
//			String message) {
//		ProgressDialog progressDialog = new ProgressDialog(context);
//		progressDialog.setMessage(message);
//		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//		progressDialog.setCancelable(true);
//		progressDialog.setIndeterminate(true);
//		return progressDialog;
//	}
	
	public static class SpinnerProgressDialog {
		private Dialog dialog;
//		private View titleContainer;
		private TextView mMessageView;
		private TextView mTitleView;

		public SpinnerProgressDialog(Dialog dialog,
				TextView titleView, TextView messageView) {
			this.dialog = dialog;
//			this.titleContainer = titleContainer;
			this.mMessageView = messageView;
			this.mTitleView = titleView;
		}

		public void show() {
			dialog.show();
		}

		public void hide() {
			dialog.hide();
		}
		
		public void setCancelable(boolean flag) {
			dialog.setCancelable(flag);
		}

		public void dismiss() {
			dialog.dismiss();
		}

		public void setMessage(String text) {
			mMessageView.setText(text);
		}

		public void setTitle(String text) {
			if (text != null) {
				mTitleView.setVisibility(View.VISIBLE);
			} else {
				mTitleView.setVisibility(View.GONE);
			}
			mTitleView.setText(text);
		}

	}
	public static final SpinnerProgressDialog getProgressDialog(
			Context context, String title, String message) {
		final Dialog dialog = new Dialog(context,android.R.style.Theme_Light_NoTitleBar);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		View view = LayoutInflater.from(context).inflate(
				R.layout.rd_progress_dialog_spinning, null);
		dialog.setContentView(view);
		dialog.getWindow().setLayout(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT);
		dialog.getWindow().setBackgroundDrawableResource(
				android.R.color.transparent);
		dialog.setCancelable(true);
		
		TextView titleView = (TextView) dialog
				.findViewById(R.id.title_text_view);

		TextView messageView = (TextView) dialog
				.findViewById(R.id.message_text_view);
		if (title != null) {
			titleView.setText(title);
		} else {
			titleView.setText(context.getString(R.string.dialog_default_title));
		}

		if (message != null) {
			messageView.setText(message);
		}

//		float textSizeDialogTitle = context.getResources()
//				.getDimensionPixelSize(R.dimen.text_size_dialog_title);
//		float textSize3 = context.getResources().getDimensionPixelSize(
//				R.dimen.text_size_3);
//		SharedPreferences sharedPreferences = PreferenceManager
//				.getDefaultSharedPreferences(context);
//		float factor = sharedPreferences.getFloat(
//				Constants.KEY_FONT_FACTOR_OTHETRS,
//				Constants.DEFAULT_FONT_FACTOR_OTHETRS);
//
//		titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, factor
//				* textSizeDialogTitle);
//		messageView.setTextSize(TypedValue.COMPLEX_UNIT_PX, factor * textSize3);

		return new SpinnerProgressDialog(dialog, titleView,
				messageView);
	}

	public static void showAlertMessage(Context context, String message) {

		final AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(message)
				.setCancelable(false)
				.setPositiveButton(context.getString(android.R.string.ok),
						new DialogInterface.OnClickListener() {
							public void onClick(final DialogInterface dialog,
									final int id) {

							}
						});
		final AlertDialog alert = builder.create();
		alert.show();
	}

	public static void showAlertMessage(Context context, String message,
			OnClickListener onClickListener) {

		final AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(message)
				.setCancelable(false)
				.setPositiveButton(context.getString(android.R.string.ok),
						onClickListener);
		final AlertDialog alert = builder.create();
		alert.show();
	}
}
